﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Homework05
{
    /* 作业5:5.显示杨辉三角
    i
    1 0 0 0 0
    1 1 0 0 0           
    1 2 1 0 0        
    1 3 3 1 0       
    1 4 6 4 1   */
    internal class Homework05
    {
        static void Main(string[] args)
        {
            //定义数组
            int[,] arr = new int[5, 5];
            //数组全部赋0
            for (int i = 0; i < arr.GetLength(0); i++)
            {
                for (int j = 0; j < arr.GetLength(1); j++)
                {
                    arr[i, j] = 0;
                }
            }

            for (int i = 0; i < arr.GetLength(0); i++)
            {
                for (int j = 0; j <= i; j++)
                {
                    if (i == j || j == 0)
                    {
                        arr[i, j] = 1;
                    }
                    else
                    {
                        arr[i, j] = arr[i - 1, j] + arr[i - 1, j - 1];
                    }
                }
            }
            Console.WriteLine("杨辉三角:");
            //打印杨辉三角
            for (int i = 0; i < arr.GetLength(0); i++)
            {
                for (int j = 0; j < arr.GetLength(1); j++)
                {
                    Console.Write($"{arr[i,j]} ");
                }
                Console.WriteLine();
            }
        }
    }
}
